package com.ruoyi.project.wx.controller;

import com.ruoyi.common.utils.bootdo.PageUtils;
import com.ruoyi.common.utils.bootdo.Query;
import com.ruoyi.common.utils.bootdo.R;
import com.ruoyi.project.wx.domain.SetExpressDO;
import com.ruoyi.project.wx.service.SetExpressService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 快递鸟设置
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2019-07-05 17:08:29
 */
 
@Controller
@RequestMapping("/wx/setExpress")
public class SetExpressController {
	@Autowired
	private SetExpressService setExpressService;
	
	@GetMapping()
	@RequiresPermissions("wx:setExpress:setExpress")
	String SetExpress(){
	    return "wx/setExpress/setExpress";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("wx:setExpress:setExpress")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<SetExpressDO> setExpressList = setExpressService.list(query);
		int total = setExpressService.count(query);
		PageUtils pageUtils = new PageUtils(setExpressList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("wx:setExpress:add")
	String add(){
	    return "wx/setExpress/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("wx:setExpress:edit")
	String edit(@PathVariable("id") String id,Model model){
		SetExpressDO setExpress = setExpressService.get(id);
		model.addAttribute("setExpress", setExpress);
	    return "wx/setExpress/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("wx:setExpress:add")
	public R save(SetExpressDO setExpress){
		if(setExpressService.save(setExpress)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("wx:setExpress:edit")
	public R update( SetExpressDO setExpress){
		setExpressService.update(setExpress);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("wx:setExpress:remove")
	public R remove( String id){
		if(setExpressService.remove(id)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("wx:setExpress:batchRemove")
	public R remove(@RequestParam("ids[]") String[] ids){
		setExpressService.batchRemove(ids);
		return R.ok();
	}
	
}
